<template>
	<view>
		<view>
			<form @submit="formSubmit" @reset="formReset">
				<view class="uni-form-item uni-column">
					<view class="title">商店名</view>
					<input class="uni-input" name="name" placeholder="这是一个输入框" />
				</view>
				<view class="uni-form-item uni-column">
					<view class="title">商店code</view>
					<input class="uni-input" name="code" placeholder="这是一个输入框" />
				</view>
				<view class="uni-form-item uni-column">
					<view class="title">联系电话</view>
					<input class="uni-input" name="phone" placeholder="这是一个输入框" />
				</view>
				<view class="uni-form-item uni-column">
					<view class="title">营业执照</view>
					<input class="uni-input" name="license" placeholder="这是一个输入框" />
				</view>
				<view class="uni-form-item uni-column">
					<view class="title">地址</view>
					<input class="uni-input" name="address" placeholder="这是一个输入框" />
				</view>
				<view class="uni-form-item uni-column">
					<view class="title">商店简介</view>
					<input class="uni-input" name="description" placeholder="这是一个输入框" />
				</view>
				<uImg ref="upimg" :limit="limitNum" :fileKeyName="name" :uImgList.sync="uImgList" />
				<view class="uni-btn-v">
					<button form-type="submit">Submit</button>
					<button type="default" form-type="reset">Reset</button>
				</view>
			</form>
		</view>
	</view>
</template>
<script>
	import uImg from '@/components/image/uploadImg.vue';
	export default {
		components: {
			uImg
		},
		data() {
			return {
				msg: '',
				length: 140,
				limitNum: 1,
				name: '', //上传的名字
				uImgList: [],
				base64ImgList: [],
			}
		},
		methods: {
			formSubmit: function(e) {
				this.uImgList.forEach((item) => {
					this.$utils.urlTobase64(item).then((base64Url) => {
						this.base64ImgList.push(base64Url)
					})
				})
				window.console.log("len", this.base64ImgList)
				var formdata = e.detail.value
				// uni.showModal({
				// 	content: '表单数据内容：' + JSON.stringify(formdata) + JSON.stringify(this.uImgList),
				// 	showCancel: false
				// });
				if (this.base64ImgList.length > 0) {
					formdata.avater = this.base64ImgList[0]
				}
				uni.showLoading({
					title: '上传中...',
					mask: false
				});
				this.$api.addShop(formdata).then(() => {
					uni.showToast({
						title: "success",
						icon: 'none'
					});
				}).catch(() => {
					uni.showToast({
						title: "fail",
						icon: 'none'
					});
				}).complete(() => {
					uni.hideLoading()
				})
			},
			formReset: function(e) {
				console.log('清空数据')
			}
		}
	}
</script>

<style>
	.uni-form-item .title {
		padding: 20rpx 0;
	}
</style>
